﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Ebc.DesignerDsl.CustomCode
{
    public class ConnectionSelectionProperty
    {
        private Func<ITypeDescriptorContext, IEnumerable<Tuple<string, Type>>> getSelectedTypes;
        private Func<ITypeDescriptorContext, IEnumerable<Tuple<string, Type>>> getOtherTypes;
        private Action<Tuple<string, Type>, SelectedItemType> setSelectedItem;
        private Func<string> getString;

        public ConnectionSelectionProperty(Func<ITypeDescriptorContext, IEnumerable<Tuple<string, Type>>> getSelectedTypes, 
            Func<ITypeDescriptorContext, IEnumerable<Tuple<string, Type>>> getOtherTypes,
            Action<Tuple<string, Type>, SelectedItemType> setSelectedItem,
            Func<string> getString)
        {
            this.getOtherTypes = getOtherTypes;
            this.getSelectedTypes = getSelectedTypes;
            this.setSelectedItem = setSelectedItem;
            this.getString = getString;
        }

        public IEnumerable<Tuple<string, Type>> GetSelectedTypes(ITypeDescriptorContext context)
        {
            return this.getSelectedTypes(context);
        }

        public IEnumerable<Tuple<string, Type>> GetOtherTypes(ITypeDescriptorContext context)
        {
            return this.getOtherTypes(context);
        }

        public void SetSelectedItem(Tuple<string, Type> value, SelectedItemType type)
        {
            this.setSelectedItem(value, type);
        }

        public override string ToString()
        {
            return this.getString();
        }
    }

    public enum SelectedItemType
    {
        CreatedNew,
        UsedSelectedType,
        UsedOtherType
    }
}